package com.xiaoye.qbproject.controller.qbzt;

import com.xiaoye.qbproject.controller.base.BaseController;
import com.xiaoye.qbproject.domain.AjaxResult;
import com.xiaoye.qbproject.domain.SubjectBlbc;
import com.xiaoye.qbproject.page.TableDataInfo;
import com.xiaoye.qbproject.service.SubjectBlbcService;
import com.xiaoye.qbproject.vo.SubjectBlbcVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/subjectBlbc")
public class SubjectBlbcController extends BaseController {
    @Autowired
    private SubjectBlbcService subjectBlbcService;

    @RequestMapping("/list")
    public TableDataInfo list(SubjectBlbcVo subjectBlbcVo) {
        startPage();
        List<SubjectBlbcVo>list =  subjectBlbcService.getList(subjectBlbcVo);
        return getDataTable(list);
    }

    /**
     * @param subjectBlbcVo
     * @description: 添加专题与兵力编程关系
     * @author: ChenYao
     * @return: com.xiaoye.qbproject.domain.AjaxResult
     * @ceateDate: 2025/2/12 下午12:47
     */

    @PostMapping
    public AjaxResult add(@RequestBody SubjectBlbcVo subjectBlbcVo) {
        String subjectId = subjectBlbcVo.getSubjectId();
        if (StringUtils.isBlank(subjectId)) {
            return error("专题ID不能为空");
        }
        List<String> blbcIds = subjectBlbcVo.getBlbcIds();
        if (blbcIds == null || blbcIds.isEmpty()) {
            return error("兵力编程ID不能为空");
        }
        subjectBlbcService.add(subjectBlbcVo);
        return success();
    }

    @DeleteMapping
    public AjaxResult delete(@RequestBody SubjectBlbcVo subjectBlbcVo) {
                String subjectId = subjectBlbcVo.getSubjectId();
        if (StringUtils.isBlank(subjectId)) {
            return error("专题ID不能为空");
        }
        List<String> blbcIds = subjectBlbcVo.getBlbcIds();
        if (blbcIds == null || blbcIds.isEmpty()) {
            return error("兵力编程ID不能为空");
        }
        subjectBlbcService.delSubjectBlbc(subjectBlbcVo);
        return success();
    }

}
